package org.agony2d.view.core 
{
	import org.agony2d.core.agony_internal;
	import org.agony2d.notify.AEvent;
	import org.agony2d.notify.Notifier;
	import org.agony2d.renderer.IView;
	import org.agony2d.view.Fusion;
	
	use namespace agony_internal;
	
public class Component extends AgonySprite
{
	
	public function Component()
	{
		UIManager.registerComp(this)
		m_notifier = new Notifier()
		m_interactive = m_visible = true
	}
	
	final public function get layer() : int { return (this.parent) ? this.parent.getChildIndex(this) : -1 }
	
	final public function get spaceWidth() : Number { return (m_spaceWidth <= 0 || isNaN(m_spaceWidth)) ? this.width : m_spaceWidth }
	final public function set spaceWidth( v:Number ) : void { m_spaceWidth = v }
	
	final public function get spaceHeight() : Number { return (m_spaceHeight <= 0 || isNaN(m_spaceHeight)) ? this.height : m_spaceHeight }
	final public function set spaceHeight( v:Number ) : void { m_spaceHeight = v }
	
	override public function get visible() : Boolean{ return m_visible }
	override public function set visible( b:Boolean ) : void 
	{
		super.visible = m_visible = b
		m_notifier.dispatchDirectEvent(AEvent.VISIBLE_CHANGE)
	}
	
	public function get interactive() : Boolean { return m_interactive }
	public function set interactive( b:Boolean ) : void
	{
		m_interactive = b
		m_notifier.dispatchDirectEvent(AEvent.INTERACTIVE_CHANGE)
	}
	
	final public function bePartOf ( c:IComponent ) : Boolean
	{
		var FN:Fusion
		
		if (c == m_proxy)
		{
			return true
		}
		FN = IComponent(m_proxy).fusion
		while (FN)
		{
			if (FN == c)
			{
				return true;
			}
			FN = FN.fusion;
		}
		return false;
	}
	
	override public function reset() : void
	{
		super.reset()
		if (!m_visible || !m_interactive)
		{
			super.visible = m_visible = m_interactive = true
		}
		this.filters = null
	}
	
	override agony_internal function dispose() : void
	{
		m_spaceWidth = m_spaceHeight = NaN
		m_notifier.dispose()
		m_proxy = null
		super.dispose()
		this.recycle()
	}
	
	agony_internal function recycle() : void
	{
	}
	
	agony_internal var m_notifier:Notifier
	agony_internal var m_proxy:IView
	agony_internal var m_cid:uint
	agony_internal var m_spaceWidth:Number, m_spaceHeight:Number
	agony_internal var m_interactive:Boolean, m_visible:Boolean
}
}